#include "stdafx.h"
#include "InputMgr.h"
#include "InputListener.h"

namespace a2d
{
//------------------------------------------------------------------

	
	void InputMgr::Init()
	{
	}

	void InputMgr::Close()
	{
		if ( !m_Listener.empty() )
			m_Listener.clear();
	}

	void InputMgr::AddListener(InputListener *Listener)
	{
		m_Listener.push_back(Listener);
	}

#define FORLISTERER(x)							\
	for each (auto listener in m_Listener)		\
	{											\
		if ( listener && listener->Enable)		\
		{										\
			if ( listener->x )					\
				return;							\
		}										\
	}

	void InputMgr::MouseButton(int button, int action, int mods)
	{
		if ( button >= MOUSE_BUTTON_MAX ) return;
		eMouseButton btn = (eMouseButton)button;
		FORLISTERER(MouseButton(btn, (eStateAction)action, (eMODE)mods));
	}
	void InputMgr::CursorPosition(double x, double y)
	{
		FORLISTERER(CursorPosition(x, y));
	}
	void InputMgr::MouseScroll(double x, double y)
	{
		FORLISTERER(MouseScroll(signed int(y)));
	}

	void InputMgr::Key(int key, int scancode, int action, int mods)
	{
		FORLISTERER(Key(key, scancode, (eStateAction)action, (eMODE)mods));
	}
	void InputMgr::Char(unsigned int codepoint)
	{
		FORLISTERER(Char((wchar_t)codepoint));
	}
	void InputMgr::CharMode(unsigned int codepoint, int mods)
	{
		FORLISTERER(CharMode((wchar_t)codepoint, (eMODE)mods));
	}

#undef FORLISTERER

//------------------------------------------------------------------
} // namespace a2d
